package cn.iocoder.yudao.module.dbit.controller.admin.jobresumeinfo;

import cn.iocoder.yudao.module.dbit.service.resumeinfo.ResumeInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.dbit.controller.admin.jobresumeinfo.vo.*;
import cn.iocoder.yudao.module.dbit.dal.dataobject.jobresumeinfo.JobResumeInfoDO;
import cn.iocoder.yudao.module.dbit.service.jobresumeinfo.JobResumeInfoService;

@Tag(name = "管理后台 - 简历投递")
@RestController
@RequestMapping("/dbit/job-resume-info")
@Validated
public class JobResumeInfoController {

    @Resource
    private JobResumeInfoService jobResumeInfoService;



    @GetMapping("/create")
    @Operation(summary = "创建简历投递")
//    @PreAuthorize("@ss.hasPermission('dbit:job-resume-info:create')")
    public CommonResult<Integer> createJobResumeInfo(@RequestParam("jobId")Integer jobId) {
        return success(jobResumeInfoService.createJobResumeInfo(jobId));
    }

    @PutMapping("/update")
    @Operation(summary = "更新简历投递")
    @PreAuthorize("@ss.hasPermission('dbit:job-resume-info:update')")
    public CommonResult<Boolean> updateJobResumeInfo(@Valid @RequestBody JobResumeInfoSaveReqVO updateReqVO) {
        jobResumeInfoService.updateJobResumeInfo(updateReqVO);
        return success(true);
    }

    @GetMapping("/update-status")
    @Operation(summary = "更新简历投递状态")
    public CommonResult<Boolean> updateJobResumeInfoStatus(@RequestParam("id") Integer id, @RequestParam("status") Integer status) {
        jobResumeInfoService.updateJobResumeInfoStatus(id, status);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除简历投递")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('dbit:job-resume-info:delete')")
    public CommonResult<Boolean> deleteJobResumeInfo(@RequestParam("id") Integer id) {
        jobResumeInfoService.deleteJobResumeInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得简历投递")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('dbit:job-resume-info:query')")
    public CommonResult<JobResumeInfoRespVO> getJobResumeInfo(@RequestParam("id") Integer id) {
        JobResumeInfoDO jobResumeInfo = jobResumeInfoService.getJobResumeInfo(id);
        return success(BeanUtils.toBean(jobResumeInfo, JobResumeInfoRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得简历投递分页")
    @PreAuthorize("@ss.hasPermission('dbit:job-resume-info:query')")
    public CommonResult<PageResult<JobResumeInfoRespVO>> getJobResumeInfoPage(@Valid JobResumeInfoPageReqVO pageReqVO) {
        PageResult<JobResumeInfoRespVO> pageResult = jobResumeInfoService.getJobResumeInfoPage(pageReqVO);
        return success(pageResult);
    }


    @GetMapping("/export-excel")
    @Operation(summary = "导出简历投递 Excel")
    @PreAuthorize("@ss.hasPermission('dbit:job-resume-info:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportJobResumeInfoExcel(@Valid JobResumeInfoPageReqVO pageReqVO,
                                         HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<JobResumeInfoDO> list = jobResumeInfoService.getJobResumeInfoPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "简历投递.xls", "数据", JobResumeInfoRespVO.class,
//                        BeanUtils.toBean(list, JobResumeInfoRespVO.class));
    }
}